﻿ <%@ WebHandler Language="C#" Class="Login" %>

using System;
using System.Web;
using Maticsoft.BLL;

public class Login : IHttpHandler,System.Web.SessionState.IRequiresSessionState   
{
    HttpRequest Request;
    HttpResponse Response;
    HttpServerUtility Server;
    HttpCookie Cookie;
    public void ProcessRequest(HttpContext context)
    {
        context.Response.Buffer = true;
        context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
        context.Response.AddHeader("pragma", "no-cache");
        context.Response.AddHeader("cache-control", "");
        context.Response.CacheControl = "no-cache";
        context.Response.ContentType = "text/plain";
        Request = context.Request;
        Response = context.Response;
        Server = context.Server;

        //string userName =  PageValidate.InputText(decodeSTR(Request["txtUsername"].ToString()), 30);
        //string Password = PageValidate.InputText(decodeSTR(Request["txtPassword"].ToString()), 30);
        try
        {
            string userName = Request["txtUsername"].ToString();
            string Password = Request["txtPass"].ToString();
            Maticsoft.BLL.userinfo uInfoBLL = new userinfo();
            System.Data.DataTable dt = uInfoBLL.GetList("loginCode='" + userName + "' and password ='" + Password + "'").Tables[0];
            bool checkPass = false;
            if (dt.Rows.Count > 0)
            {
                checkPass = true;
            }
            if (!checkPass)
            {
                Response.Write("用户名或密码错误！");
            }
            else
            {
                Maticsoft.Model.userinfo loginUser = uInfoBLL.GetModel(Convert.ToInt32(dt.Rows[0]["id"]));
                context.Session["loginUser"] = loginUser;
                Response.Write("登录成功！");
            }
        }
        catch (Exception ex)
        {
            Response.Write("网络错误，请稍候再试！");
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}